﻿namespace GoodAdmin.CodeGenerator;
/// <summary>
/// 代码生成控制器
/// </summary>
[ApiDescriptionSettings("CodeGenerator", Tag = "代码生成")]
[Route("/codeGen/base")]
public class CodeGenController: IDynamicApiController
{
    private readonly IDbService _dbService;
    private readonly ICodeGenService _codeGenService;

    public CodeGenController(IDbService dbService, ICodeGenService codeGenService)
    {
        _dbService = dbService;
        _codeGenService = codeGenService;

    }
    /// <summary>
    /// 数据表选择器
    /// </summary>
    /// <returns></returns>
    [HttpGet("dbConfigSelector")]
    [DisplayName("数据库选择器")]
    public List<DbConfigOutput> DbConfigSelector()
    {
        return _dbService.GetDbConfig();
    }
    /// <summary>
    /// 数据表选择器
    /// </summary>
    /// <returns></returns>
    [HttpGet("tableSelector")]
    [DisplayName("数据表选择器")]
    public List<DbTableInfo> TableSelector(string ConfigId)
    {
        return _dbService.GetTables(ConfigId);
    }

    /// <summary>
    /// 查询模板基础信息
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("page")]
    [DisplayName("查询模板基础信息")]
    public async Task<SqlSugarPagedList<CodeGenDataSimple>> Page([FromQuery]CodeGenDataPageInput input)
    {
        return await _codeGenService.GetBaseList(input);
    }

    /// <summary>
    /// 根据基础信息id查询表单数据
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("getDetailDatas")]
    [DisplayName("根据基础信息id查询表单数据")]
    public async Task<CodeGenData> GetDetailData([FromQuery] BaseIdInput input)
    {
        return await _codeGenService.GetDetail(input.Id);
    }

    /// <summary>
    /// 获取数据表字段信息
    /// </summary>
    /// <param name="ConfigId"></param>
    /// <param name="TableNames"></param>
    /// <returns></returns>
    [HttpGet("getTableFields")]
    [DisplayName("获取数据表字段信息")]
    public dynamic GetTableFields([FromQuery]TableFieldQueryInput input)
    {
        return _dbService.GetTableField(input.ConfigId, input.TableNames);
    }
}